home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / exe / main2.c < prev    next >
C/C++ Source or Header  |  2004-05-09  |  6KB  |  225 lines

  1. /*-------------------------------------------------------------
  2.   main2.c : TClockExeMain, and initializing functions
  3.   (C) 1997-2003 Kazuto Sato
  4.   Please read readme.txt about the license.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "tclock.h"
  10.  
  11. /* Globals */
  12.  
  13. int TClockExeMain(void);
  14.  
  15. char g_mydir[MAX_PATH];     // path to tclock.exe
  16. BOOL g_bIniSetting = FALSE; // save setting to ini file?
  17. char g_inifile[MAX_PATH];   // ini file name
  18. int  g_winver;              // windows version
  19. UINT g_uTaskbarRestart;     // taskbar recreating message
  20.  
  21. /* Statics */
  22.  
  23. static void InitTClockMain(void);
  24. static BOOL CheckTCDLL(void);
  25. static void InitTextColor(void);
  26. static void InitFormat(void);
  27.  
  28. /*-------------------------------------------
  29.    main routine
  30. ---------------------------------------------*/
  31. int TClockExeMain(void)
  32. {
  33.     MSG msg;
  34.     WNDCLASS wndclass;
  35.     HWND hwnd;
  36.     
  37.     // not to execute the program twice
  38.     hwnd = GetTClockMainWindow();
  39.     if(hwnd != NULL)
  40.     {
  41.         CheckCommandLine(hwnd, TRUE);
  42.         return 1;
  43.     }
  44.     
  45.     if(!CheckTCDLL()) { return 1; }
  46.     
  47.     if(FindWindow("ObjectBar Toolbar", NULL))
  48.     {
  49.         MessageBox(NULL, "ObjectBar is running",
  50.             "Error", MB_OK|MB_ICONEXCLAMATION);
  51.         return 1;
  52.     }
  53.     
  54.     InitTClockMain();
  55.     
  56.     // register a window class
  57.     wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  58.     wndclass.lpfnWndProc   = WndProc;
  59.     wndclass.cbClsExtra    = 0;
  60.     wndclass.cbWndExtra    = 0;
  61.     wndclass.hInstance     = g_hInst;
  62.     wndclass.hIcon         = LoadIcon(g_hInst, "MYICON");
  63.     wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  64.     wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  65.     wndclass.lpszMenuName  = NULL;
  66.     wndclass.lpszClassName = CLASS_TCLOCKMAIN;
  67.     RegisterClass(&wndclass);
  68.     
  69.     // create a hidden window
  70.     hwnd = CreateWindowEx(0,
  71.         CLASS_TCLOCKMAIN, TITLE_TCLOCKMAIN, WS_OVERLAPPEDWINDOW,
  72.         CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  73.         NULL, NULL, g_hInst, NULL);
  74.     // ShowWindow(hwnd, SW_SHOW);
  75.     // UpdateWindow(hwnd);
  76.     
  77.     CheckCommandLine(hwnd, FALSE);
  78.     
  79.     while(GetMessage(&msg, NULL, 0, 0))
  80.     {
  81.         if(g_hDlgAbout && IsDialogMessage(g_hDlgAbout, &msg)) ;
  82.         else
  83.         {
  84.             TranslateMessage(&msg);
  85.             DispatchMessage(&msg);
  86.         }
  87.     }
  88.     
  89.     UnregisterClass(CLASS_TCLOCKMAIN, g_hInst);
  90.     
  91.     return msg.wParam;
  92. }
  93.  
  94. /*-------------------------------------------
  95.   initialize variables, format, etc.
  96. ---------------------------------------------*/
  97. void InitTClockMain(void)
  98. {
  99.     // get the path where .exe is positioned
  100.     GetModuleFileName(g_hInst, g_mydir, MAX_PATH);
  101.     del_title(g_mydir);
  102.     
  103.     g_bIniSetting = FALSE;
  104.     SetMyRegStr(NULL, "ExePath", g_mydir);
  105.     
  106.     // ini file name
  107.     strcpy(g_inifile, g_mydir);
  108.     add_title(g_inifile, "tclock.ini");
  109.     g_bIniSetting = TRUE;
  110. /*  g_bIniSetting = IsFile(g_inifile); */
  111.     
  112.     g_winver = CheckWinVersion();
  113.     
  114.     // Message of the taskbar recreating
  115.     // Special thanks to Mr.Inuya
  116.     g_uTaskbarRestart = RegisterWindowMessage("TaskbarCreated");
  117.     
  118.     DelMyRegKey("OnContextMenu"); // temporarily
  119.     
  120.     InitTextColor();
  121.     
  122.     InitFormat();
  123. }
  124.  
  125. /*-------------------------------------------
  126.   Check version of dll
  127. ---------------------------------------------*/
  128. BOOL CheckTCDLL(void)
  129. {
  130.     char str[80];
  131.     GetTClockVersion(str);
  132.     if(strcmp(str, TCLOCKVERSION) != 0)
  133.     {
  134.         MessageBox(NULL, "Invalid file version: tcdll.tclock",
  135.             "Error", MB_OK|MB_ICONEXCLAMATION);
  136.         return FALSE;
  137.     }
  138.     return TRUE;
  139. }
  140.  
  141. /*------------------------------------------------
  142.   for Luna theme of Windows XP
  143. --------------------------------------------------*/
  144. void InitTextColor(void)
  145. {
  146.     char s[80];
  147.     char themekey[] =
  148.         "Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager";
  149.     
  150.     if(GetMyRegStr(NULL, "ForeColor", s, 20, "") > 0) return;
  151.     
  152.     GetRegStr(HKEY_CURRENT_USER, themekey,
  153.         "DllName", s, 80, "");
  154.     if(strstr(s, "\\luna.msstyles") != NULL)
  155.     {
  156.         GetRegStr(HKEY_CURRENT_USER, themekey,
  157.             "ColorName", s, 80, "");
  158.         if(strcmp(s, "NormalColor") == 0)
  159.             SetMyRegLong(NULL, "ForeColor", RGB(255,255,255));
  160.     }
  161. }
  162.  
  163. /*------------------------------------------------
  164.   initialize format string
  165. --------------------------------------------------*/
  166. void InitFormat(void)
  167. {
  168.     char s[BUFSIZE_FORMAT];
  169.     BOOL parts[NUM_FORMATPART];
  170.     RECT rc;
  171.     HWND hwnd;
  172.     BOOL bbreak;
  173.     int ilang;
  174.     int i;
  175.     
  176.     if(GetMyRegStr("", "Format", s, BUFSIZE_FORMAT, "") > 0)
  177.         return;
  178.     
  179.     ilang = GetMyRegLong("", "Locale", (int)GetUserDefaultLangID());
  180.     if(GetMyRegStr("", "Locale", s, 20, "") == 0)
  181.         SetMyRegLong("", "Locale", ilang);
  182.     
  183.     InitAutoFormat(ilang); // common/autoformat.c
  184.     
  185.     for(i = 0; i < NUM_FORMATPART; i++)
  186.         parts[i] = FALSE;
  187.     
  188.     parts[PART_YEAR] = TRUE;
  189.     parts[PART_MONTH] = TRUE;
  190.     parts[PART_DAY] = TRUE;
  191.     parts[PART_WEEKDAY] = TRUE;
  192.     parts[PART_HOUR] = TRUE;
  193.     parts[PART_MINUTE] = TRUE;
  194.     parts[PART_SECOND] = TRUE;
  195.     
  196.     bbreak = FALSE;
  197.     hwnd = GetTaskbarWindow();
  198.     if(hwnd != NULL)
  199.     {
  200.         GetClientRect(hwnd, &rc);
  201.         // vertical task bar
  202.         if(rc.right < rc.bottom) bbreak = TRUE;
  203.         
  204.         if(g_winver&WINXP)
  205.         {
  206.             hwnd = FindWindowEx(hwnd, NULL, "TrayNotifyWnd", NULL);
  207.             if(hwnd)
  208.             {
  209.                 RECT rc;
  210.                 GetClientRect(hwnd, &rc);
  211.                 if(rc.bottom - rc.top > 32) bbreak = TRUE;
  212.             }
  213.         }
  214.     }
  215.     
  216.     parts[PART_BREAK] = bbreak;
  217.     
  218.     AutoFormat(s, parts);  // common/autoformat.c
  219.     
  220.     SetMyRegStr("", "Format", s);
  221.     
  222.     SetMyRegLong("", "Kaigyo", parts[PART_BREAK]);
  223. }
  224.  
  225.